package com.autohelper.dto;

public class ResultDto<T> {
    private int code;
    private String message;
    private T data;

    public ResultDto() {
        this.code = 0;
        this.message = "";
        this.data = null;
    }

    public ResultDto(T data) {
        this.code = 0;
        this.message = "";
        this.data = data;
    }

    public ResultDto(int code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public static <T> ResultDto<T> newSuccess(T data) {
        return new ResultDto<>(data);
    }

    public static <T> ResultDto<T> newError(String message) {
        return new ResultDto<>(500, message, null);
    }

    public int getCode() {
        return code;
    }

    public String getMessage() {
        return message;
    }

    public T getData() {
        return data;
    }

    public boolean success() {
        return code == 0;
    }

    public boolean error() {
        return this.code != 0;
    }
}
